cmake_minimum_required(VERSION 3.16)
set(CMAKE_TOOLCHAIN_FILE cmake_module/cortex_m4.cmake)
enable_language(ASM C CXX)

project(BNO055Driver)

include(cmake_module/bundle_static_library.cmake)

set(CMAKE_VERBOSE_MAKEFILE ON)


set(CMAKE_CXX_STANDARD 17)


add_definitions(
        -DSTM32F40_41xxx
        -DUSE_STDPERIPH_DRIVER
        -DHSE_VALUE=24000000
        -DUSE_USB_OTG_FS
        -DUSE_FULL_ASSERT
        -D__VFP_FP__
        -DBNO055_API
)


include_directories(
        inc
        .
        lib/etl
        lib/STM32_USB_Device_Library/inc
        lib/STM32F4xx_StdPeriph_Driver/inc
)
add_subdirectory(connectivity)
add_subdirectory(lib/STM32F4xx_StdPeriph_Driver)
#add_subdirectory(lib/fatfs)
#add_subdirectory(src/bno055)
add_subdirectory(src)
add_subdirectory(system)
#add_subdirectory(src/fatfs_example)
#add_subdirectory(src/sdio_fs)


#
#add_executable(${PROJECT_NAME}.elf
#        ${SOURCES}
#        src/main.cpp
#        src/bno055/future.cpp
#        src/bno055/BNO055.cpp
#
#        src/l3gd20/l3gd20.cpp
#        src/mpu9250/mpu9250.cpp  system/debug.cpp system/debug.h)

#bundle_static_library(all_libs
#        connectivity
#        std_periph_driver
#        #        mpu9250 l3gd20   bno055 sdio_fs
##        main
#        bno055  mpu9250 sdio_fs
#        system
#        )


add_executable(${PROJECT_NAME}.elf src/main.cpp)

target_link_libraries(${PROJECT_NAME}.elf
        -Wl,--whole-archive
        #        all_libs
        connectivity
        std_periph_driver
        #        mpu9250   bno055 sdio_fs
        #        main
        l3gd20
        bno055  mpu9250 ms5611
        system


        #        ${CMAKE_SOURCE_DIR}/lib/STM32F4xx_StdPeriph_Driver/libSTM32F4xx_StdPeriph_Driver.a
        -Wl,--no-whole-archive

        #        fatfs
        #        fatfs_example

        )


add_custom_target(${PROJECT_NAME}.bin ALL
        DEPENDS ${PROJECT_NAME}.elf
        COMMAND ${CMAKE_OBJCOPY} -O binary ${PROJECT_NAME}.elf ${PROJECT_NAME}.bin
        COMMAND ${CMAKE_SIZE} ${PROJECT_NAME}.elf
        )
#
#add_custom_target(${PROJECT_NAME}.sym ALL
#        DEPENDS ${PROJECT_NAME}.elf
#        COMMAND ${CMAKE_OBJDUMP} -t ${PROJECT_NAME}.elf > ${PROJECT_NAME}.sym)

#add_custom_target(${PROJECT_NAME}.lst
#        DEPENDS ${PROJECT_NAME}.elf
#        COMMAND ${CMAKE_OBJDUMP} -D ${PROJECT_NAME}.elf > ${PROJECT_NAME}.lst)
#

#add_custom_target(${PROJECT_NAME}.dump
#        DEPENDS ${PROJECT_NAME}.elf
#        COMMAND ${CMAKE_OBJDUMP} -SD ${PROJECT_NAME}.elf > ${PROJECT_NAME}.dump)
#
#



